<?php
namespace Home\Controller;
use Think\Controller;
class PublicController extends Controller {
    public function login(){
       $this->display();
    }
	 public function register(){
       $this->display();
    }
	//登陆
	public function loginAction(){
		
		$name = $_POST["name"];
		$pass = $_POST["password"];
		$result =M('user')->where("name = '$name' and password = '$pass'")->select();
		$this->assign("result",$result);
		if(!empty($result)){
			$_SESSION["name"] = $result[0]["name"];
			$this->redirect("index/index");
		}else{
			$this->redirect("Public/register");
			
		}
	}
	//退出
	public function loginout(){
		
		//清空session
		session('name',null); // 删除name
		
		//进入登录界面
		$this->redirect("Public/login");
	}
	public function registerAction(){
		$code = $_POST["code"];
		$info = M('user')->add($_POST);
		if(($info>0)&&$this->check_verify($code)){
			$_SESSION["name"] = $_POST["name"];
			$this->redirect("index/index");
		}else{
			$this->redirect("Public/register");
			
		}
		
	}
	//验证码
	public function yanzma(){
		
		$Verify =     new \Think\Verify();
		// 验证码字体大小
		$Verify->fontSize = 30;
		// 验证码位数
		$Verify->length   = 3;
		// 关闭验证码杂点
		$Verify->useNoise = false;
		$Verify->entry();

	}
	// 检测输入的验证码是否正确，$code为用户输入的验证码字符串
	public function check_verify($code, $id = ''){
		$verify = new \Think\Verify();
		return $verify->check($code, $id);
	}
	//无限极分类输出
	public function wxjshow(){
		$wuxianzhu = M('fenlei')->where("p_id = '0,'")->select();
		
		
		foreach($wuxianzhu as $k=>$v){
			
			$id = $v['id'];
			$res = M('fenlei')->field('name,id')->where("p_id = '0,$id,'")->select();
			$wuxianzi[$v['name']] = $res;
			
			foreach($res as  $k1=>$v1){
				
				$ziid = $v1['id'];
				$arr = M('fenlei')->field('name,id')->where("p_id = '0,$id,$ziid,'")->select();
				$wuxiantotal[$v['name']][$v1['name']] = $arr;
					
			}
			
		}
		

		$this->assign("wuxiantotal",$wuxiantotal);
	}
	
}